package com.wlgc.mapper;

import com.github.pagehelper.Page;
import com.wlgc.entity.User;
import com.wlgc.entity.dto.UserPageQueryDTO;
import com.wlgc.entity.vo.UserPageVO;
import org.apache.ibatis.annotations.*;
import org.springframework.security.core.parameters.P;

@Mapper
public interface UserMapper {
    //获取User
    @Select("select uid,username,password,avatar_path from user_student_view where sid=#{sid}")
    public User getUserBySid(@Param("sid") int sid);

    @Select("select uid,username,password,avatar_path from user where uid=#{uid} ")
    public User getUserByUid(@Param("uid") int uid);

    @Select("select uid,username,password,avatar_path from user_student_view where email=#{email}")
    public User getUserByEmail(@Param("email") String email);

    //向用户表插入用户
    @Insert("insert into user(username,password,avatar_path) values(#{username},#{password},#{avatarPath})")
    public int addUser(@Param("username") String username, @Param("password") String password, @Param("avatarPath") String avatarPath);

    //向用户学生表插入用户学生对应关系
    @Insert("insert into user_student(uid,sid) values((select uid from user where username=#{username}),#{sid})")
    public int add_user_student(@Param("username") String username, @Param("sid") int sid);

    //给予用户角色
    @Insert("insert into user_role(rid,uid) values((select rid from role where role_key=#{role_key}),(select uid from user where username=#{username}))")
    public int add_user_role(@Param("username") String username, @Param("role_key") String role_key);

    //修改头像路径
    @Update("update  user set avatar_path =#{avatar_path} where uid=#{uid}")
    public int changeAvatar_Path(int uid, String avatar_path);
    //获取用户头像路径
    @Select("select avatar_path from user where username =#{username}")
    public String getAvatar_PathByUsername(String username);

    //根据班级分页查询用户

    Page<UserPageVO> pageQuery(UserPageQueryDTO userPageQueryDTO);
}
